/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaVenta.java
 *
 * Created on 22-dic-2011, 11:12:15
 */
package invsys.Vistas;

import invsys.Controladores.ControlCliente;
import invsys.Controladores.ControlCredito;
import invsys.Controladores.ControlDetalleCredito;
import invsys.Controladores.ControlDetalleVenta;
import invsys.Controladores.ControlProducto;
import invsys.Controladores.ControlUsuario;
import invsys.Controladores.ControlVariable;
import invsys.Controladores.ControlVenta;
import invsys.Modelo.Cliente;
import invsys.Modelo.Credito;
import invsys.Modelo.DetalleCredito;
import invsys.Modelo.DetalleVenta;
import invsys.Modelo.Persona;
import invsys.Modelo.Producto;
import invsys.Modelo.Usuario;
import invsys.Modelo.Variable;
import invsys.Modelo.Venta;
import invsys.Utilidades.ManejadorBaseDatos;
import invsys.Utilidades.ValidarorVistas;
import invsys.Principal;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;


/**
 *
 * @author dell
 */
public class VistaVenta extends javax.swing.JDialog {
private static DefaultTableModel dtm = new DefaultTableModel();
private static DefaultTableModel dtm2 = new DefaultTableModel();
 private static DefaultTableModel dtm1= new DefaultTableModel();
ValidarorVistas vistas= new ValidarorVistas();

DecimalFormat precio= new DecimalFormat(".00");
SimpleDateFormat fechas= new SimpleDateFormat("dd/MM/yyyy");
    /** Creates new form VistaVenta */
    public VistaVenta(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
           initComponents();
           this.setLocationRelativeTo(this);
           
           
            iniciar();
              Listar();
      
      
    }
private void iniciar() {
         
            vuelto.setText("");
            abonoe.setText("");
            desccuento.setText("0");
            abonocr.setText("");
            dtm1.setNumRows(0);
            subtotal.setText("");
            iva.setText("");
            txtDireccion.setText("");
            txtid.setText("");
            txtTelefono.setText("");
            txtNombre.setText("");
            total();      
        
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Clientes = new javax.swing.JDialog();
        jPanel9 = new invsys.Imagenes.Fondo.panel("buscarclientes.png");
        jButton2 = new javax.swing.JButton();
        ComboCliente = new javax.swing.JComboBox();
        BuscarCliente = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        Clientestabla = new org.jdesktop.swingx.JXTable(dtm);
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        CantidadProducto = new javax.swing.JDialog();
        cantidad = new javax.swing.JTextField();
        ventas = new javax.swing.ButtonGroup();
        jPanel7 =  new invsys.Imagenes.Fondo.panel("vender.png");
        jPanel1 = new invsys.Imagenes.Fondo.panel("transparente.png");
        jLabel1 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        txtid = new javax.swing.JTextField();
        txtTelefono = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jPanel10 = new javax.swing.JPanel();
        efectivo = new javax.swing.JCheckBox();
        tarjeta = new javax.swing.JCheckBox();
        cheque = new javax.swing.JCheckBox();
        credito = new javax.swing.JCheckBox();
        jPanel2 = new invsys.Imagenes.Fondo.panel("transparente.png");
        numeroVenta = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        BsucarProducto = new javax.swing.JTextField();
        fecha = new com.toedter.calendar.JDateChooser();
        jLabel7 = new javax.swing.JLabel();
        jPanel3 = new invsys.Imagenes.Fondo.panel("transparente.png");
        jScrollPane1 = new javax.swing.JScrollPane();
        productos = new org.jdesktop.swingx.JXTable(dtm2);
        jPanel4 = new invsys.Imagenes.Fondo.panel("transparente.png");
        jScrollPane2 = new javax.swing.JScrollPane();
        venta = new org.jdesktop.swingx.JXTable(dtm1);
        jButton6 = new javax.swing.JButton();
        Total = new javax.swing.JTextField();
        cbarticulo = new javax.swing.JComboBox();
        jPanel15 = new invsys.Imagenes.Fondo.panel("transparente.png");
        txtResponsable = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        observaciones = new javax.swing.JTextArea();
        txtNomResponsable = new javax.swing.JTextField();
        jLabel29 = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        iva = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        desccuento = new javax.swing.JTextField();
        subtotal = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel11 = new invsys.Imagenes.Fondo.panel("transparente.png");
        abonoe = new javax.swing.JTextField();
        vuelto = new javax.swing.JTextField();
        jPanel12 = new invsys.Imagenes.Fondo.panel("transparente.png");
        abonocr = new javax.swing.JTextField();
        saldoact = new javax.swing.JTextField();
        saldoant = new javax.swing.JTextField();
        jPanel13 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel21 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jPanel14 = new javax.swing.JPanel();
        jLabel24 = new javax.swing.JLabel();
        jTextField10 = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        jTextField12 = new javax.swing.JTextField();
        jComboBox2 = new javax.swing.JComboBox();
        jDateChooser2 = new com.toedter.calendar.JDateChooser();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        mensaje = new javax.swing.JLabel();
        jButton7 = new javax.swing.JButton();
        jaja = new javax.swing.JMenuBar();
        p = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        Clientes.setModal(true);

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Busquda Cliente", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18), new java.awt.Color(0, 0, 255))); // NOI18N
        jPanel9.setForeground(new java.awt.Color(0, 0, 255));

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/Salir.png"))); // NOI18N
        jButton2.setText("Salir");
        jButton2.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/Sali1.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        ComboCliente.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nombre:", "Codigo:" }));

        BuscarCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                BuscarClienteKeyReleased(evt);
            }
        });

        jLabel14.setForeground(new java.awt.Color(0, 0, 255));
        jLabel14.setText("Buscar Por:");

        dtm.addColumn("Idientficacion");
        dtm.addColumn("Nombre");
        dtm.addColumn("Direccion");
        dtm.addColumn("Telefono");
        Clientestabla.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        Clientestabla.setEditable(false);
        Clientestabla.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ClientestablaMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                ClientestablaMouseEntered(evt);
            }
        });
        Clientestabla.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                ClientestablaKeyPressed(evt);
            }
        });
        jScrollPane4.setViewportView(Clientestabla);

        jButton8.setText("Nuevo");

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/agregar.png"))); // NOI18N
        jButton9.setText("Agregar");
        jButton9.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/agregar1.png"))); // NOI18N
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jButton9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addGap(4, 4, 4)
                        .addComponent(ComboCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BuscarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BuscarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ComboCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton8)
                    .addComponent(jButton9)))
        );

        javax.swing.GroupLayout ClientesLayout = new javax.swing.GroupLayout(Clientes.getContentPane());
        Clientes.getContentPane().setLayout(ClientesLayout);
        ClientesLayout.setHorizontalGroup(
            ClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        ClientesLayout.setVerticalGroup(
            ClientesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        CantidadProducto.setUndecorated(true);

        cantidad.setFont(new java.awt.Font("SansSerif", 1, 90));
        cantidad.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        cantidad.setText("0");
        cantidad.setToolTipText("Ingrese La cantidad y Luego Enter");
        cantidad.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), "CAntidad de Producto", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N
        cantidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cantidadActionPerformed(evt);
            }
        });
        cantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cantidadKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                cantidadKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout CantidadProductoLayout = new javax.swing.GroupLayout(CantidadProducto.getContentPane());
        CantidadProducto.getContentPane().setLayout(CantidadProductoLayout);
        CantidadProductoLayout.setHorizontalGroup(
            CantidadProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(cantidad, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
        );
        CantidadProductoLayout.setVerticalGroup(
            CantidadProductoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(cantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 128, Short.MAX_VALUE)
        );

        jPanel7.setFocusCycleRoot(true);
        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), "Relaizar Venta", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 1, 18))); // NOI18N
        jPanel7.setFont(new java.awt.Font("Tahoma", 1, 11));
        jPanel7.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jPanel7FocusGained(evt);
            }
        });
        jPanel7.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jPanel7KeyPressed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del Cliente"));

        jLabel1.setText("Nombre:");

        txtNombre.setEditable(false);

        jLabel2.setText("Identifiaion:");

        jLabel3.setText("Direccion:");

        jLabel4.setText("Telefono:");

        txtDireccion.setEditable(false);

        txtid.setEditable(false);

        txtTelefono.setEditable(false);

        jButton1.setText(" ♠");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Forma de Pago"));

        ventas.add(efectivo);
        efectivo.setSelected(true);
        efectivo.setText("Efectivo");
        efectivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                efectivoActionPerformed(evt);
            }
        });

        ventas.add(tarjeta);
        tarjeta.setText("Tarjeta");
        tarjeta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tarjetaActionPerformed(evt);
            }
        });

        ventas.add(cheque);
        cheque.setText("Cheque");
        cheque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chequeActionPerformed(evt);
            }
        });

        ventas.add(credito);
        credito.setText("Credito");
        credito.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                creditoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(efectivo)
                    .addComponent(tarjeta))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 5, Short.MAX_VALUE)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cheque)
                    .addComponent(credito))
                .addGap(15, 15, 15))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(efectivo)
                    .addComponent(credito))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cheque)
                    .addComponent(tarjeta))
                .addContainerGap(8, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtid, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)
                    .addComponent(txtNombre, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(txtDireccion)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(82, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4)
                    .addComponent(txtid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
            .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos De La Venta", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        numeroVenta.setEditable(false);
        numeroVenta.setForeground(new java.awt.Color(0, 51, 255));

        jLabel5.setText("Factura:");

        jLabel6.setText("Articulo:");

        BsucarProducto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                BsucarProductoKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                BsucarProductoKeyReleased(evt);
            }
        });

        jLabel7.setText("Fecha de Compra:");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Articulos Inventario"));

        dtm2.addColumn("Codigo");
        dtm2.addColumn("Tipo");
        dtm2.addColumn("Nombre");
        dtm2.addColumn("Descripción");
        dtm2.addColumn("Precio");
        dtm2.addColumn("Cantidad");
        dtm2.addColumn("StockMin");
        productos.setAutoStartEditOnKeyStroke(false);
        productos.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        productos.setEditable(false);
        productos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                productosMouseClicked(evt);
            }
        });
        productos.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                productosComponentResized(evt);
            }
        });
        productos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                productosKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(productos);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 512, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Articulos a Vender"));

        dtm1.addColumn("Codigo");
        dtm1.addColumn("Nombre");
        dtm1.addColumn("Descripcion");
        dtm1.addColumn("Precio");
        dtm1.addColumn("Cantdad");
        dtm1.addColumn("Costo");
        venta.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        venta.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                ventaKeyPressed(evt);
            }
        });
        jScrollPane2.setViewportView(venta);

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/cerrar.png"))); // NOI18N
        jButton6.setText("Quitar");
        jButton6.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/cerrar1.png"))); // NOI18N
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton6)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 512, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        Total.setEditable(false);
        Total.setFont(new java.awt.Font("Tw Cen MT Condensed Extra Bold", 1, 36));
        Total.setForeground(new java.awt.Color(0, 153, 0));
        Total.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        Total.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "TOTAL", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        Total.setPreferredSize(new java.awt.Dimension(16, 51));

        cbarticulo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nombre:", "Codigo:" }));

        jPanel15.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Responsable", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        txtResponsable.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel28.setText("Identificacion:");

        observaciones.setColumns(20);
        observaciones.setRows(5);
        observaciones.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jScrollPane3.setViewportView(observaciones);

        txtNomResponsable.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel29.setText("Nombre:");

        jLabel30.setText("obserbaciones:");

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel30)
                    .addComponent(jLabel28)
                    .addComponent(jLabel29))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtResponsable, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                    .addComponent(txtNomResponsable, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel29, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNomResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel28, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel30, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12))
        );

        iva.setEditable(false);
        iva.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel15.setText("%");

        desccuento.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        desccuento.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                desccuentoKeyReleased(evt);
            }
        });

        subtotal.setEditable(false);
        subtotal.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel11.setText("Subtotal:");

        jLabel9.setText("Descuento:");

        jLabel8.setText("Iva:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbarticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BsucarProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(22, 22, 22)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(fecha, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel11))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(iva, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(subtotal, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(desccuento, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel15))))
                            .addComponent(Total, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
                            .addComponent(jPanel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(numeroVenta, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
                        .addGap(22, 22, 22))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(cbarticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(BsucarProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(fecha, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(8, 8, 8)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                            .addComponent(numeroVenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(iva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(desccuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(subtotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(20, 20, 20)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        abonoe.setFont(new java.awt.Font("Tw Cen MT Condensed Extra Bold", 1, 24));
        abonoe.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        abonoe.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Abono", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        abonoe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                abonoeActionPerformed(evt);
            }
        });
        abonoe.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                abonoeKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                abonoeKeyReleased(evt);
            }
        });

        vuelto.setEditable(false);
        vuelto.setFont(new java.awt.Font("Tw Cen MT Condensed Extra Bold", 1, 24)); // NOI18N
        vuelto.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        vuelto.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Su vuelto es:", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(abonoe, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(vuelto, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(abonoe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vuelto, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Efectivo", jPanel11);

        abonocr.setFont(new java.awt.Font("Tw Cen MT Condensed Extra Bold", 1, 36));
        abonocr.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        abonocr.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Abono", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
        abonocr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                abonocrActionPerformed(evt);
            }
        });
        abonocr.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                abonocrKeyReleased(evt);
            }
        });

        saldoact.setFont(new java.awt.Font("Tw Cen MT Condensed Extra Bold", 1, 12));
        saldoact.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        saldoact.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "SALDO ACTUAL:", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 0, 8))); // NOI18N
        saldoact.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saldoactActionPerformed(evt);
            }
        });
        saldoact.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                saldoactKeyReleased(evt);
            }
        });

        saldoant.setFont(new java.awt.Font("Tw Cen MT Condensed Extra Bold", 1, 12));
        saldoant.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        saldoant.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "SALDO ANTERIOR", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Agency FB", 0, 8))); // NOI18N
        saldoant.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saldoantActionPerformed(evt);
            }
        });
        saldoant.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                saldoantKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(abonocr, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(saldoact, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saldoant, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel12Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(abonocr, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                    .addGroup(jPanel12Layout.createSequentialGroup()
                        .addComponent(saldoact, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saldoant, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Credito", jPanel12);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel21.setText("Nr Tarjeta");

        jLabel22.setText("Monto:");

        jLabel23.setText("Tipo Tarjeta");

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel21)
                    .addComponent(jLabel23))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextField8, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE))
                .addContainerGap(144, Short.MAX_VALUE))
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel21, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(39, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Tarjeta", jPanel13);

        jLabel24.setText("Nro Cheque:");

        jLabel25.setText("Monto");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel26.setText("Banco:");

        jLabel27.setText("Fecha Venc");

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel25)
                    .addComponent(jLabel26))
                .addGap(18, 18, 18)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTextField12, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel24)
                    .addComponent(jLabel27))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(127, Short.MAX_VALUE))
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel27, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel26, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jDateChooser2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Cheque", jPanel14);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/Vender.png"))); // NOI18N
        jButton4.setText("Vender");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/1327507759_edit-clear.png"))); // NOI18N
        jButton5.setText("Cancelar");
        jButton5.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/1327507765_edit-clear.png"))); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/Salir.png"))); // NOI18N
        jButton3.setText("Salir");
        jButton3.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/Sali1.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        mensaje.setFont(new java.awt.Font("Tahoma", 1, 12));
        mensaje.setForeground(new java.awt.Color(255, 0, 0));
        mensaje.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/invsys/Imagenes/Botones/1327507488_import.png"))); // NOI18N
        jButton7.setText("Nueva Venta");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 531, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(mensaje, javax.swing.GroupLayout.PREFERRED_SIZE, 321, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createSequentialGroup()
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(15, 15, 15))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addComponent(mensaje, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE)
                        .addGap(10, 10, 10)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
                            .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(17, 17, 17))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        p.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pActionPerformed(evt);
            }
        });

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        jMenuItem1.setText("jMenuItem1");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        p.add(jMenuItem1);

        jaja.add(p);

        setJMenuBar(jaja);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
 this.dispose();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
RealizarVenta();     

// TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
 iniciar();
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
    int x = venta.getSelectedRow();
           if(x < 0){
           mensaje.setText("Selecione primero el producto ");
        }else{ 
                 try {
                    String e= dtm1.getValueAt(x, 0).toString();
                    Producto p=ControlProducto.BuscarProducto(e);
                    int ahoravalor=Integer.parseInt(dtm1.getValueAt(x,4).toString());
                    int pos=0;
                    double ca=0;
                    for(int i=0;i<dtm2.getRowCount();i++){
                    String e1= dtm2.getValueAt(i, 0).toString();
                    if(e1.equals(e)){
                        int canti=Integer.parseInt(dtm2.getValueAt(i, 5).toString());
                        int cantant =canti+ahoravalor;
                        dtm2.setValueAt(cantant,i, 5);
                    }          
                    }          
                } catch (SQLException ex) {
                    Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
                }
          String e= dtm1.getValueAt(x, 0).toString();               
           dtm1.removeRow(x);
           total();
           }
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
Clientes.setSize(550,320);
Clientes.setLocationRelativeTo(this);
Clientes.setVisible(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void BuscarClienteKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_BuscarClienteKeyReleased
    if(ComboCliente.getSelectedItem().toString().equals("Codigo:")){
           listaClienteId(BuscarCliente.getText());
      }else{
          listaClientenombre(BuscarCliente.getText());
      }
        // TODO add your handling code here:
    }//GEN-LAST:event_BuscarClienteKeyReleased

    private void ClientestablaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ClientestablaMouseClicked
  
        // TODO add your handling code here:
    }//GEN-LAST:event_ClientestablaMouseClicked

    private void ClientestablaMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ClientestablaMouseEntered
   
           
        // TODO add your handling code here:
    }//GEN-LAST:event_ClientestablaMouseEntered

    private void productosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_productosMouseClicked

    
        
        // TODO add your handling code here:
    }//GEN-LAST:event_productosMouseClicked

    private void cantidadKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cantidadKeyReleased

        vistas.validarnumero(cantidad, mensaje);
                // TODO add your handling code here:
    }//GEN-LAST:event_cantidadKeyReleased

    private void cantidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cantidadActionPerformed
AsignarProduto();
CantidadProducto.setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_cantidadActionPerformed

    private void desccuentoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_desccuentoKeyReleased
        try { if(!desccuento.getText().isEmpty()){
            vistas.validarnumero(desccuento, mensaje);
            Variable var =ControlVariable.buscarVariables("02");
             if(var.getValor()<Double.parseDouble(desccuento.getText())/100){
             mensaje.setText("Porsentaje invalido max Des"+var.getValor()*100+"%");
             }
             total(); 
             abonoe.setText("");
             vuelto.setText("");
           
             }else{
              desccuento.setText("0");
              }
                    // TODO add your handling code here:
        } catch (SQLException ex) {
            Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_desccuentoKeyReleased

    private void efectivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_efectivoActionPerformed
             
            jTabbedPane1.setEnabledAt(0,true);
            jTabbedPane1.setEnabledAt(1,false);
            jTabbedPane1.setEnabledAt(2,false);
            jTabbedPane1.setEnabledAt(3,false);
            jTabbedPane1.setSelectedIndex(0);
        
        // TODO add your handling code here:
    }//GEN-LAST:event_efectivoActionPerformed

    private void creditoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_creditoActionPerformed
            jTabbedPane1.setEnabledAt(1,true);
            jTabbedPane1.setEnabledAt(0,false);
            jTabbedPane1.setEnabledAt(2,false);
            jTabbedPane1.setEnabledAt(3,false);
            jTabbedPane1.setSelectedIndex(1);
        // TODO add your handling code here:
    }//GEN-LAST:event_creditoActionPerformed

    private void tarjetaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tarjetaActionPerformed
          jTabbedPane1.setEnabledAt(2,true);
            jTabbedPane1.setEnabledAt(1,false);
            jTabbedPane1.setEnabledAt(0,false);
            jTabbedPane1.setEnabledAt(3,false);
            jTabbedPane1.setSelectedIndex(2);
        // TODO add your handling code here:
    }//GEN-LAST:event_tarjetaActionPerformed

    private void chequeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chequeActionPerformed
            jTabbedPane1.setEnabledAt(3,true);
            jTabbedPane1.setEnabledAt(1,false);
            jTabbedPane1.setEnabledAt(2,false);
            jTabbedPane1.setEnabledAt(0,false);
            jTabbedPane1.setSelectedIndex(3);
        // TODO add your handling code here:
    }//GEN-LAST:event_chequeActionPerformed

    private void abonoeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_abonoeActionPerformed
 vuelto();
        // TODO add your handling code here:
    }//GEN-LAST:event_abonoeActionPerformed

    private void BsucarProductoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_BsucarProductoKeyReleased
if(cbarticulo.getSelectedItem().toString().equals("Codigo:")){
           listaProductoId(BsucarProducto.getText());
           ventanaEspejo();
      }else{
          listaproductonombre(BsucarProducto.getText());
          ventanaEspejo();
      }        // TODO add your handling code here:
    }//GEN-LAST:event_BsucarProductoKeyReleased

    private void abonoeKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_abonoeKeyReleased
       vuelto();
        // TODO add your handling code here:
    }//GEN-LAST:event_abonoeKeyReleased

    private void abonocrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_abonocrActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_abonocrActionPerformed

    private void abonocrKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_abonocrKeyReleased
  abono();      
  // TODO add your handling code here:
    }//GEN-LAST:event_abonocrKeyReleased

    private void saldoactActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saldoactActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_saldoactActionPerformed

    private void saldoactKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_saldoactKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_saldoactKeyReleased

    private void saldoantActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saldoantActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_saldoantActionPerformed

    private void saldoantKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_saldoantKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_saldoantKeyReleased

    private void productosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_productosKeyPressed

        if (evt.getKeyCode() == KeyEvent.VK_ENTER){
             int x=productos.getSelectedRow();
        int s= Integer.parseInt(dtm2.getValueAt(x,5).toString());
        double s1= Double.parseDouble(dtm2.getValueAt(x,6).toString());
          if(!txtNombre.getText().isEmpty() && !txtDireccion.getText().isEmpty() && !txtTelefono.getText().isEmpty() && !txtid.getText().isEmpty() ){
        
              
           if(s<=0){
           JOptionPane.showMessageDialog(this,"Existencia agotada de este Producto");
           }else{
               if(s1>s){
                   JOptionPane.showMessageDialog(this,"Recuerde que solo quedan: "+s+" producttos de:"+dtm2.getValueAt(x,2).toString());
                     ventanacantidad();
                       }else{
       ventanacantidad();
               }   }
       }else{
        mensaje.setText("Selecione un Cliente (F1)");
       }
     }else{
        if(evt.getKeyCode() == KeyEvent.VK_TAB){
           
            venta.requestFocus();
        }}
        
        
        
    }//GEN-LAST:event_productosKeyPressed

    private void cantidadKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cantidadKeyPressed
     
            if (evt.getKeyCode() == KeyEvent.VK_ESCAPE){
     
       CantidadProducto.setVisible(false);
       
      
     }
        // TODO add your handling code here:
    }//GEN-LAST:event_cantidadKeyPressed

    private void ClientestablaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ClientestablaKeyPressed
if (evt.getKeyCode() == KeyEvent.VK_ENTER){
    AgregarClientes();
  }
        // TODO add your handling code here:
    }//GEN-LAST:event_ClientestablaKeyPressed

    private void productosComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_productosComponentResized
   
    }//GEN-LAST:event_productosComponentResized

    private void BsucarProductoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_BsucarProductoKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER){
     productos.selectAll();
     productos.requestFocus();
       
      
     }  
// TODO add your handling code here:
    }//GEN-LAST:event_BsucarProductoKeyPressed

    private void jPanel7KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel7KeyPressed
       // TODO add your handling code here:
    }//GEN-LAST:event_jPanel7KeyPressed

    private void pActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pActionPerformed

Clientes.setSize(550,320);
Clientes.setLocationRelativeTo(this);
Clientes.setVisible(true);      // TODO add your handling code here:
    }//GEN-LAST:event_pActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed

Clientes.setSize(550,320);
Clientes.setLocationRelativeTo(this);
Clientes.setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
VistaVenta ven =new VistaVenta(null, rootPaneCheckingEnabled);
ven.setVisible(true);
// TODO add your handling code here:
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jPanel7FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jPanel7FocusGained
        try {
            numeroVenta.setText(ControlVenta.ultimafactura());
     
     
        } catch (Exception ex) {
            Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jPanel7FocusGained

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
AgregarClientes();
       // TODO add your handling code here:
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
Clientes.dispose();
// TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void ventaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ventaKeyPressed
          if (evt.getKeyCode() == KeyEvent.VK_TAB){
     
     abonoe.requestFocus();
       
      
     }    // TODO add your handling code here:
    }//GEN-LAST:event_ventaKeyPressed

    private void abonoeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_abonoeKeyPressed
       if (evt.getKeyCode() == KeyEvent.VK_TAB){
     
     desccuento.requestFocus();
       
      
     }        // TODO add your handling code here:
    }//GEN-LAST:event_abonoeKeyPressed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
     
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                VistaVenta dialog = new VistaVenta(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField BsucarProducto;
    private javax.swing.JTextField BuscarCliente;
    private javax.swing.JDialog CantidadProducto;
    private javax.swing.JDialog Clientes;
    private org.jdesktop.swingx.JXTable Clientestabla;
    private javax.swing.JComboBox ComboCliente;
    private javax.swing.JTextField Total;
    private javax.swing.JTextField abonocr;
    private javax.swing.JTextField abonoe;
    private javax.swing.JTextField cantidad;
    private javax.swing.JComboBox cbarticulo;
    private javax.swing.JCheckBox cheque;
    private javax.swing.JCheckBox credito;
    private javax.swing.JTextField desccuento;
    private javax.swing.JCheckBox efectivo;
    private com.toedter.calendar.JDateChooser fecha;
    private javax.swing.JTextField iva;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private com.toedter.calendar.JDateChooser jDateChooser2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField12;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private javax.swing.JMenuBar jaja;
    private javax.swing.JLabel mensaje;
    private static javax.swing.JTextField numeroVenta;
    private javax.swing.JTextArea observaciones;
    private javax.swing.JMenu p;
    private org.jdesktop.swingx.JXTable productos;
    private javax.swing.JTextField saldoact;
    private javax.swing.JTextField saldoant;
    private javax.swing.JTextField subtotal;
    private javax.swing.JCheckBox tarjeta;
    private javax.swing.JTextField txtDireccion;
    private static javax.swing.JTextField txtNomResponsable;
    private javax.swing.JTextField txtNombre;
    private static javax.swing.JTextField txtResponsable;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtid;
    private org.jdesktop.swingx.JXTable venta;
    private javax.swing.ButtonGroup ventas;
    private javax.swing.JTextField vuelto;
    // End of variables declaration//GEN-END:variables
public static void listarClientes(){
        try {
            dtm.setNumRows(0);
            ControlCliente.listarCliente();
                   Iterator it =  ControlCliente.getCliente().iterator();
                   while (it.hasNext()) {
                               Cliente cont= (Cliente) it.next();
                               String[] fila = {cont.getId(),cont.getNombre()+" "+cont.getApellido(), cont.getDireccion(), cont.getTelefono()};
                                 dtm.addRow(fila);
       
}
        } catch (SQLException ex) {
            Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
        }

}
   private void listaClientenombre(String text) {
        try {
            dtm.setNumRows(0);
             ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
             mbd.conectar();          
             ControlCliente.con=mbd.getConexion();
             ControlCliente.listarCliente1("SELECT *FROM clientes WHERE nombre LIKE '%"+text+"%'");
             Iterator iter1= ControlCliente.getCliente().iterator();
             while(iter1.hasNext()){
                 Cliente cl =(Cliente)iter1.next();
                String[] fila = {cl.getId(), cl.getNombre()+" "+cl.getApellido(), cl.getDireccion(),cl.getTelefono()};
                dtm.addRow(fila);
        
             }
        } catch (SQLException ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void listaClienteId(String text) {
        try {
            dtm.setNumRows(0);
             ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
             mbd.conectar();          
             ControlCliente.con=mbd.getConexion();
             ControlCliente.listarCliente1("SELECT *FROM clientes WHERE id LIKE '%"+text+"%'");
             Iterator iter1= ControlCliente.getCliente().iterator();
             while(iter1.hasNext()){
                 Cliente cl =(Cliente)iter1.next();
                String[] fila = {cl.getId(), cl.getNombre()+" "+cl.getApellido(), cl.getDireccion(),cl.getTelefono()};
                dtm.addRow(fila);
        
             }
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
}
       private void listaproductonombre(String text) {
        try {
            dtm2.setNumRows(0);
             ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
             mbd.conectar();          
             ControlProducto.con=mbd.getConexion();
             ControlProducto.listarProducto1("SELECT *FROM productos WHERE nombre LIKE '%"+text+"%'");
             Iterator iter1= ControlProducto.getProducto().iterator()
                     ;
             while(iter1.hasNext()){
                Producto pro = (Producto) iter1.next();
                               int stm = (int) pro.getStockMin();
                               int can = (int) pro.getCantidad();
                               String[] fila = {pro.getCodigo(), pro.getTipo(), pro.getNombre(),pro.getDescripcion(), pro.getPrecio()+"",can+"", stm+""};
                                 dtm2.addRow(fila);
        
             }
        } catch (SQLException ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void listaProductoId(String text) {
        try {
            dtm2.setNumRows(0);
             ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
             mbd.conectar();          
             ControlProducto.con=mbd.getConexion();
             ControlProducto.listarProducto1("SELECT *FROM productos WHERE codigo LIKE '%"+text+"%'");
             Iterator iter1= ControlProducto.getProducto().iterator()
                     ;
             while(iter1.hasNext()){
                Producto pro = (Producto) iter1.next();
                               int stm = (int) pro.getStockMin();
                               int can = (int) pro.getCantidad();
                               String[] fila = {pro.getCodigo(), pro.getTipo(), pro.getNombre(),pro.getDescripcion(), pro.getPrecio()+"",can+"", stm+""};
                                 dtm2.addRow(fila);
        
             }
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
}
      public static void listaProductos() {
        try {
            dtm2.setNumRows(0);
            ManejadorBaseDatos mbd = ManejadorBaseDatos.getInstancia();
            mbd.conectar();      
            ControlProducto.con = mbd.getConexion();
            ControlProducto.listarProducto();
            Iterator it =  ControlProducto.getProducto().iterator();
                   while (it.hasNext()) {
                               Producto pro = (Producto) it.next();
                               int stm = (int) pro.getStockMin();
                               int can = (int) pro.getCantidad();
                               String[] fila = {pro.getCodigo(), pro.getTipo(), pro.getNombre(),pro.getDescripcion(), pro.getPrecio()+"",can+"", stm+""};
                                 dtm2.addRow(fila);
              
                    }
        } catch (SQLException ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
        }
 }

    private void AsignarProduto() {
         if(cantidad.getText().equals("")){
       mensaje.setText("Digite Cantidad ");
        } else{   
        int x = productos.getSelectedRow();
           if(x < 0){
             mensaje.setText("Selecione primero el producto ");
        }else{
                    try {
                    String e= dtm2.getValueAt(x, 0).toString();
                    Producto p=ControlProducto.BuscarProducto(e);
                    double ahoravalor=Double.parseDouble(dtm2.getValueAt(x,5).toString());
                    double pre= p.getPrecio();
                    int can=Integer.parseInt(cantidad.getText());
                    double valor =pre*can;
                    boolean rep=false;
                    String[] filarep=null;
                    int pos=0;
                    int ca=0;
                    double va=0;
                    for(int i=0;i<dtm1.getRowCount();i++){
                    String e1= dtm1.getValueAt(i, 0).toString();
                    if(e1.equals(e)){
                        rep=true;
                        String cantat=dtm1.getValueAt(i, 4).toString();
                        Producto p1=ControlProducto.BuscarProducto(e1);
                        int canact=Integer.parseInt(cantidad.getText());
                        int cantant =Integer.parseInt(cantat);
                        int cantidadActual=canact+cantant;                    
                        double valoract =p1.getPrecio()*cantidadActual;
                        String[] fila={p1.getCodigo(),p1.getNombre(),p1.getDescripcion(),"$"+p1.getPrecio()+"",cantidadActual+"","$"+valoract+""};
                        ca=cantidadActual;
                        va=valoract;
                        filarep=fila;
                        pos=i;
                           
                    }
                    
                    }
                    if(!rep){
                        if(ahoravalor>=can){
                    String[] fila={p.getCodigo(),p.getNombre(),p.getDescripcion(),"$"+p.getPrecio()+"",can+"","$"+valor+""};
                    int canti=(int)ahoravalor-can;   
                    
                    dtm2.setValueAt(canti,x, 5);
                    dtm1.addRow(fila);
                    total();rep=false;
                    cantidad.setText("0");
                        }else{
                        JOptionPane.showMessageDialog(this," no hay la cantidad  nesesario de "+p.getNombre()+"s");
                        }
                    }else{
                    if(ahoravalor>=can){
                    double canti1=ahoravalor-can;   
                    int canti=(int) canti1;
                    dtm2.setValueAt(canti,x, 5);
                    dtm1.setValueAt(ca, pos, 4);
                    dtm1.setValueAt(va, pos, 5);
                    total();
                    cantidad.setText("0");
                    rep=false;
                    }else{
                        JOptionPane.showMessageDialog(this," no hay la cantidad  nesesario de "+p.getNombre()+"s");
                        }
                    }
                   
                              
                } catch (SQLException ex) {
                    Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
                }
           }
           abonoe.setText("");
           vuelto.setText("");
           
        }
    }
     public void total(){
         double total1=0;
         fecha.setDate(new Date());
          
             if(dtm1.getRowCount()== 0){
               subtotal.setText("$0");
               iva.setText("$0");
               Total.setText("$0");
           }else{
         for(int i=0;i<dtm1.getRowCount();i++){
                try { 
                    
                    StringTokenizer sub= new StringTokenizer(dtm1.getValueAt(i,5).toString(),"$");
                    
                    double subt=Double.parseDouble(sub.nextToken());
                    total1=total1+subt;
                    String valor="";
                    valor=String.valueOf(total1);
                    subtotal.setText("$"+valor);
                    Variable var =ControlVariable.buscarVariables("01");
                    double iva1=var.getValor()*total1;
                    if(iva1<=0){
                        iva.setText("$0,0");
                    }else{
                    iva.setText("$"+precio.format(iva1)+"");}
                    double des=Double.parseDouble(desccuento.getText())/100;
                    double total=iva1+total1;
                    double totaldes=des*total;
                    total=iva1+total1-totaldes;
                    Total.setText("$"+precio.format(vistas.redondear((int)total)));
                  
                } catch (SQLException ex) {
                    Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
                }
           
         }
           }
     }
    private void vuelto() {
        if (dtm1.getRowCount()==0){
        mensaje.setText("Ingrese primero productos ala venta");
        abonoe.setText("");
        }else{
    vistas.validarnumero(abonoe, mensaje);
     if(!abonoe.getText().equals("")){
        StringTokenizer st= new StringTokenizer(Total.getText(),"$");
        StringTokenizer st1= new StringTokenizer(st.nextToken(),",");
        double t=Double.parseDouble(st1.nextToken()+"."+st1.nextToken());
       double abono=Double.parseDouble(abonoe.getText());
       double vue=abono-t;
     vuelto.setText("$ "+precio.format(vue));}else
     {vuelto.setText("");
     }
    }
    }
    private void RealizarVenta() {
        try {
            numeroVenta.setText(ControlVenta.ultimafactura());
          
                Venta v= new Venta();
               
                if(efectivo.isSelected()){
                    REgistrarEfectivo(v);
                    Principal.iniciar();
                              }else
                  if(credito.isSelected()){
                      REgistrarCredito(v);
                       Principal.iniciar();
                                   }else
                  if(tarjeta.isSelected()){
                      tarjeta();
                  }else
                  if(cheque.isSelected()){
                      cheque();
                  }
        } catch (Exception ex) {
            Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
        }
       
       
    }
    private void efectivo(Venta v) {
      
            
            
             
                try {
                    StringTokenizer st= new StringTokenizer(vuelto.getText(),"$");
                    StringTokenizer st1= new StringTokenizer(st.nextToken(),",");
                    double t=Double.parseDouble(st1.nextToken()+"."+st1.nextToken());
                    v.setEfectivo(Double.parseDouble(abonoe.getText()));
                    v.setCambio(t);
                    v.setTipoPago("Efectivo");
                    ControlVenta.RegistrarVenta(v);
                } catch (SQLException ex) {
                    Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
                } catch (Exception ex) {
                    Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
                }

                   
    }
    private void credito(Venta v) {
        Credito cr= new Credito();
        DetalleCredito dcr= new DetalleCredito();
             StringTokenizer s= new StringTokenizer(saldoact.getText(),"$");
             StringTokenizer s1= new StringTokenizer(s.nextToken(),",");
             double saldo=Double.parseDouble(s1.nextToken()+"."+s1.nextToken());
             double abono=Double.parseDouble(abonocr.getText());
               
            try {
                cr.setId(ControlCredito.ultimoCredito());
                cr.setFecha(fechas.format(fecha.getDate()));
                cr.setSaldo(saldo);
                cr.setClente(ControlCliente.BuscarClienteid(txtid.getText()));
                v.setTipoPago("Credtio");
                Cliente cli= cr.getClente();
                dcr.setCredito(cr);
                dcr.setFactura(v);
                dcr.setMonto(abono);
                dcr.setSaldo(saldo);
                dcr.setFecha(fechas.format(fecha.getDate()));
                dcr.setMovimiento("Abono");
                ControlDetalleCredito.RegistrarDetalleCredito(dcr);
                ControlCredito.RegistrarCredito(cr);
                cli.setSaldo(ControlCliente.SaldoCredito(cli.getId()));
                ControlCliente.ModificarCliente(cli,cli.getId());
                ControlVenta.RegistrarVenta(v);
                
            } catch (IOException ex) {
                Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
            }
                
                
                      
    
    }
    private void tarjeta() {
       
    }
    private void cheque() {
       
    }
    private void ventas(Venta v) {
       try {
            Producto pr;
            StringTokenizer st= new StringTokenizer(Total.getText(),"$");
            StringTokenizer st1= new StringTokenizer(st.nextToken(),",");
            StringTokenizer si= new StringTokenizer(iva.getText(),"$");
            StringTokenizer si1= new StringTokenizer(si.nextToken(),",");
           double t=Double.parseDouble(st1.nextToken()+"."+st1.nextToken());
           double iv=Double.parseDouble(si1.nextToken()+"."+si1.nextToken());
           v.setCliente(ControlCliente.BuscarClienteid(txtid.getText()));
           v.setFecha(fechas.format(fecha.getDate()));
           v.setDescuento((Double.parseDouble(desccuento.getText())/100)*t);
           v.setObservaciones(observaciones.getText());
           v.setUsuario(ControlUsuario.BuscarUsuario(txtResponsable.getText()));
           v.setNumero(numeroVenta.getText());
           v.setTotal(t);
           v.setIva(iv);   
           DetalleVenta dt=new DetalleVenta();
           for(int i=0;i<dtm1.getRowCount();i++){
                       pr = ControlProducto.BuscarProducto(dtm1.getValueAt(i, 0).toString());
                       StringTokenizer cos=new StringTokenizer(dtm1.getValueAt(i, 5).toString(),"$");
                       double sub=Double.parseDouble(cos.nextToken());
                       Producto p = ControlProducto.BuscarProducto(dtm1.getValueAt(i, 0).toString());
                       System.err.print(p.getCodigo());
                       dt.setVenta(v);
                       dt.setProducto(p);
                       dt.setCantidad(Double.parseDouble(dtm1.getValueAt(i, 4).toString()));
                       dt.setCantidadAct(pr.getCantidad());
                       dt.setSubtotal(sub);
                       Double cant = pr.getCantidad();
                       cant = cant - dt.getCantidad();
                       pr.setCantidad(cant);
                       ControlProducto.ModificarProducto(pr, pr.getCodigo());
                       dt.setCantidadFinal(cant);
                       ControlDetalleVenta.RegistrarDetalleVenta(dt);
                 
         
               }
        
            
                 
                 
         
           
                     
      
    
   } catch (IOException ex) {
                        Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (SQLException ex) {
                        Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (Exception ex) {
                        Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
                    }
   
}
    private void abono() {
        if (dtm1.getRowCount()==0){
        mensaje.setText("Ingrese primero productos ala venta");
        abonocr.setText("");
        }else{
        vistas.validarnumero(abonocr, mensaje);
        if(!abonocr.getText().equals("")){
        StringTokenizer st= new StringTokenizer(Total.getText(),"$");
        StringTokenizer st1= new StringTokenizer(st.nextToken(),",");
        double t=Double.parseDouble(st1.nextToken()+"."+st1.nextToken());
       double abono=Double.parseDouble(abonocr.getText());
       double saldact=t-abono;
       saldoact.setText(precio.format(saldact));}else{
        saldoact.setText("");
        }     
        }
    }
    private void REgistrarEfectivo(Venta v) {
       if (dtm1.getRowCount()==0){
            mensaje.setText("Ingrese primero productos ala venta");
            abonoe.setText("");
            }else{
                  if(vuelto.getText().equals("")){               
                  mensaje.setText("Ingrese El valor Recibido");
                  vuelto.requestFocus();
                  vuelto.selectAll();
                 }else{
             StringTokenizer s= new StringTokenizer(Total.getText(),"$");
             StringTokenizer s1= new StringTokenizer(s.nextToken(),",");
             double t1=Double.parseDouble(s1.nextToken()+"."+s1.nextToken());
                      double abono=Double.parseDouble(abonoe.getText());
                     if(t1>abono){
                       mensaje.setText("El Valor Es menor"); 
                       vuelto.selectAll();
                     }else{
              ventas(v);  
              efectivo(v);  
              JOptionPane.showMessageDialog(this,"Venta Realizado Con Exito");
               iniciar();
                  }
                }
                }
    }
    private void REgistrarCredito(Venta v) {
       if (dtm1.getRowCount()==0){
             mensaje.setText("Ingrese primero productos ala venta");
            abonoe.setText("");
            }else{
                if(abonocr.getText().equals("")){               
                  mensaje.setText("Ingrese El valor Del abono");
                  abonocr.requestFocus();
                  abonocr.selectAll();
                 }else{
               StringTokenizer s= new StringTokenizer(saldoact.getText(),"$");
             StringTokenizer s1= new StringTokenizer(s.nextToken(),",");
             double saldo=Double.parseDouble(s1.nextToken()+"."+s1.nextToken());
             double abono=Double.parseDouble(abonocr.getText());
             if(saldo<0){
                       mensaje.setText("El Valor Es mañor que el de pagar"); 
                       abonocr.requestFocus();
                       abonocr.selectAll();
                     }else{
                    try {
                        ventas(v);  
                        credito(v);
                        JOptionPane.showMessageDialog(this,"Venta Realizado Con Exito");
                        saldoant.setText(ControlCliente.BuscarClienteid(txtid.getText()).getSaldo()+"");
                        iniciar();
                    } catch (SQLException ex) {
                        Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
                    }
}
        }
    }
    }
    private void ventanacantidad() {
       mensaje.setText("");
       CantidadProducto.setModal(true);
       CantidadProducto.setSize(160, 140);
       CantidadProducto.setLocationRelativeTo(this);       
       CantidadProducto.setVisible(true);

    }
   public void ventanaEspejo(){
       for(int i=0;i<dtm2.getRowCount();i++){
           String e= dtm2.getValueAt(i, 0).toString();
           int cant=Integer.parseInt(dtm2.getValueAt(i,5).toString());
            for(int b=0;b<dtm1.getRowCount();b++){
           String e1=dtm1.getValueAt(b,0).toString();
           if(e1.equals(e)){
           int cant1=cant-Integer.parseInt(dtm1.getValueAt(b,4).toString());
           dtm2.setValueAt(cant1,i, 5);
           }
           }
      
       
       }
      
   }
    public static void usuario() {
      try {
             Usuario usu=ControlUsuario.BuscarUsuario(Principal.codigo.getText()); 
             txtResponsable.setText(usu.getId());
             txtNomResponsable.setText(usu.getNombre());
             numeroVenta.setText(ControlVenta.ultimafactura());
             
        } catch (Exception ex) {
            Logger.getLogger(VistaVenta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void AgregarClientes() {
              int x = Clientestabla.getSelectedRow();
        if(x <0){
            
        }else{
            try {
                String id = dtm.getValueAt(x, 0).toString();
                Cliente p = ControlCliente.BuscarClienteid(id);
                txtNombre.setText(p.getNombre());
                txtid.setText(p.getId());
                txtDireccion.setText(p.getDireccion());
                txtTelefono.setText(p.getTelefono());
                saldoant.setText(p.getSaldo()+"");
                Clientes.setVisible(false);
                listaProductos();
            } catch (SQLException ex) {
                Logger.getLogger(VistaCompra.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public static  void Listar() {
        listarClientes();
            listaProductos();
    }
}
